<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Context Sensitive Help in Any Editor -- by Rajat</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link href="../static/theme.css" rel="stylesheet" type="text/css" />
<script src="../static/content.js" type="text/javascript"></script>
</head>
<body>

<h1>Context Sensitive Help in Any Editor -- by Rajat</h1>

<p>This script makes Ctrl+2 (or another hotkey of your choice) show the help file
 page for the selected AutoHotkey command or keyword. If nothing is selected,
 the command name will be extracted from the beginning of the current line.
</p>
<p><a href="ContextSensitiveHelp.ahk">Download This Script</a> &nbsp;| &nbsp;<a href="index.htm">Other Sample Scripts</a> &nbsp;| &nbsp;<a href="../AutoHotkey.htm">Home</a></p>

<pre class="NoIndent"><em>; The hotkey below uses the clipboard to provide compatibility with the maximum
; number of editors (since ControlGet doesn't work with most advanced editors).
; It restores the original clipboard contents afterward, but as plain text,
; which seems better than nothing.</em>

$^2::
<em>; The following values are in effect only for the duration of this hotkey thread.
; Therefore, there is no need to change them back to their original values
; because that is done automatically when the thread ends:</em>
SetWinDelay 10
SetKeyDelay 0
AutoTrim, On

if A_OSType = WIN32_WINDOWS  <em>; Windows 9x</em>
    Sleep, 500  <em>; Give time for the user to release the key.</em>

C_ClipboardPrev = %clipboard%
clipboard =
<em>; Use the highlighted word if there is one (since sometimes the user might
; intentionally highlight something that isn't a command):</em>
Send, ^c
ClipWait, 0.1
if ErrorLevel &lt;&gt; 0
{
    <em>; Get the entire line because editors treat cursor navigation keys differently:</em>
    Send, {home}+{end}^c
    ClipWait, 0.2
    if ErrorLevel &lt;&gt; 0  <em>; Rare, so no error is reported.</em>
    {
        clipboard = %C_ClipboardPrev%
        return
    }
}
C_Cmd = %clipboard%  <em>; This will trim leading and trailing tabs &amp; spaces.</em>
clipboard = %C_ClipboardPrev%  <em>; Restore the original clipboard for the user.</em>
Loop, parse, C_Cmd, %A_Space%`,  <em>; The first space or comma is the end of the command.</em>
{
    C_Cmd = %A_LoopField%
    break <em>; i.e. we only need one interation.</em>
}
IfWinNotExist, AutoHotkey Help
{
    <em>; Determine AutoHotkey's location:</em>
    RegRead, ahk_dir, HKEY_LOCAL_MACHINE, SOFTWARE\AutoHotkey, InstallDir
    if ErrorLevel  <em>; Not found, so look for it in some other common locations.</em>
    {
        if A_AhkPath
            SplitPath, A_AhkPath,, ahk_dir
        else IfExist ..\..\AutoHotkey.chm
            ahk_dir = ..\..
        else IfExist %A_ProgramFiles%\AutoHotkey\AutoHotkey.chm
            ahk_dir = %A_ProgramFiles%\AutoHotkey
        else
        {
            MsgBox Could not find the AutoHotkey folder.
            return
        }
    }
    Run %ahk_dir%\AutoHotkey.chm
    WinWait AutoHotkey Help
}
<em>; The above has set the &quot;last found&quot; window which we use below:</em>
WinActivate
WinWaitActive
StringReplace, C_Cmd, C_Cmd, #, {#}
send, !n{home}+{end}%C_Cmd%{enter}
return
</pre>
</body>
</html>
